package com.example.loganalysis.controller;


import com.example.loganalysis.dao.TLoginLogDao;
import com.example.loganalysis.dao.TOperateLogDao;
import com.example.loganalysis.dao.TerminalSessionsDao;
import com.example.loganalysis.entity.TLoginLog;
import com.example.loganalysis.entity.TOperateLog;
import com.example.loganalysis.entity.TerminalSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class QueryLogController {

    private final TLoginLogDao tloginLogDao;
    private final TOperateLogDao toperateLogDao;
    private final TerminalSessionsDao terminalSessionsDao;
    @Autowired
    public QueryLogController(TLoginLogDao tloginLogDao, TOperateLogDao toperateLogDao, TerminalSessionsDao terminalSessionsDao) {
        this.tloginLogDao = tloginLogDao;
        this.toperateLogDao = toperateLogDao;
        this.terminalSessionsDao = terminalSessionsDao;
    }

    /**
     * 获取日志接口
     *

     * @return 日志列表
     */
    @CrossOrigin(origins = "http://192.168.231.31:8080")
    @RequestMapping("/query/loginlogs")
    public ResponseEntity<List<TLoginLog>> getLoginLogs() {
        List<TLoginLog> logs = tloginLogDao.queryLoginLogs();
        logs.forEach(log -> System.out.println(log.getLog_type()));
        return ResponseEntity.ok(logs);
    }

    @RequestMapping("/query/operatelogs")
    public ResponseEntity<List<TOperateLog>> getOperateLogs() {
        List<TOperateLog> logs = toperateLogDao.queryOperateLogs();
        logs.forEach(log -> System.out.println(log.getLog_type()));
        return ResponseEntity.ok(logs);
    }

    @RequestMapping("/query/terminalsessions")
    public ResponseEntity<List<TerminalSession>> getTerminalSessions() {
        List<TerminalSession> logs = terminalSessionsDao.queryTerminalSessions();
        logs.forEach(log -> System.out.println(log.getLog_type()));
        return ResponseEntity.ok(logs);
    }
}
